package com.zl.cms.dto;

import com.zl.cms.model.User;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * User: zl email:c3tc3tc3t@126.com Date: 14-1-24 Time: 下午3:40
 */
public class UserDto {
  private int id;
  /**
   * 用户登录名称
   */
  private String username;
  /**
   * 用户登录密码
   */
  private String password;
  /**
   * 用户中文名称
   */
  private String nickname;
  /**
   * 用户邮件
   */
  private String email;
  /**
   * 用户联系电话
   */
  private String phone;
  /**
   * 用户状态，0停用，1启用
   */
  private int status;


  private Date createdate;

  public Date getCreatedate() {
    return createdate;
  }

  public void setCreatedate(Date createdate) {
    this.createdate = createdate;
  }

  /**
   * 角色ids
   */
  private Integer[] roleids;
  /**
   * 组ids
   */
  private Integer[] groupids;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  @NotEmpty(message = "用户名不能为空")
  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  @NotEmpty(message = "用户密码不能为空")
  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getNickname() {
    return nickname;
  }

  public void setNickname(String nickname) {
    this.nickname = nickname;
  }

  @Email(message = "邮件格式不正确")
  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getPhone() {
    return phone;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }

  public int getStatus() {
    return status;
  }

  public void setStatus(int status) {
    this.status = status;
  }

  public Integer[] getRoleids() {
    return roleids;
  }

  public void setRoleids(Integer[] roleids) {
    this.roleids = roleids;
  }

  public Integer[] getGroupids() {
    return groupids;
  }

  public void setGroupids(Integer[] groupids) {
    this.groupids = groupids;
  }

  public UserDto() {}

  public UserDto(User user) {
    this.setEmail(user.getEmail());
    this.setId(user.getId());
    this.setPassword(user.getPassword());
    this.setPhone(user.getPhone());
    this.setUsername(user.getUsername());
    this.setStatus(user.getStatus());
    this.setNickname(user.getNickname());
    this.setCreatedate(user.getCreatedate());

  }

  public UserDto(User user, Integer[] roleids, Integer[] groupids) {
    this.setEmail(user.getEmail());
    this.setId(user.getId());
    this.setPassword(user.getPassword());
    this.setPhone(user.getPhone());
    this.setUsername(user.getUsername());
    this.setStatus(user.getStatus());
    this.setNickname(user.getNickname());
    this.setRoleids(roleids);
    this.setGroupids(groupids);
    this.setCreatedate(user.getCreatedate());
  }

  public UserDto(User user, List<Integer> roleids, List<Integer> groupids) {
    this.setEmail(user.getEmail());
    this.setId(user.getId());
    this.setPassword(user.getPassword());
    this.setPhone(user.getPhone());
    this.setUsername(user.getUsername());
    this.setStatus(user.getStatus());
    this.setNickname(user.getNickname());
    this.setRoleids(roleids.toArray(new Integer[roleids.size()]));
    this.setGroupids(groupids.toArray(new Integer[groupids.size()]));
    this.setCreatedate(user.getCreatedate());
  }

  public User getUser() {
    User u = new User();
    u.setId(this.id);
    u.setEmail(this.email);
    u.setNickname(this.nickname);
    u.setPassword(this.password);
    u.setPhone(this.phone);
    u.setStatus(this.status);
    u.setUsername(this.username);
    u.setCreatedate(new Date(System.currentTimeMillis()));
    return u;
  }

}
